VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmRefList 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Reference List"
   ClientHeight    =   5970
   ClientLeft      =   2595
   ClientTop       =   2085
   ClientWidth     =   9210
   Icon            =   "frmRefList.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5970
   ScaleWidth      =   9210
   ShowInTaskbar   =   0   'False
   Begin ITGControls.ComunionFrames fraRef 
      Height          =   5865
      Left            =   30
      Top             =   30
      Width           =   9135
      _ExtentX        =   16113
      _ExtentY        =   10345
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Reference List"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Picture         =   "frmRefList.frx":076A
      IconSize        =   24
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16777215
      Begin ITGControls.ComunionButton cmdCAll 
         Height          =   375
         Left            =   90
         TabIndex        =   7
         Top             =   5310
         Width           =   1065
         _ExtentX        =   1879
         _ExtentY        =   661
         BTYPE           =   3
         TX              =   "Check All"
         ENAB            =   -1  'True
         BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         COLTYPE         =   1
         FOCUSR          =   -1  'True
         BCOL            =   15790320
         BCOLO           =   15790320
         FCOL            =   0
         FCOLO           =   0
         MCOL            =   12632256
         MPTR            =   1
         MICON           =   "frmRefList.frx":0EE4
         UMCOL           =   -1  'True
         SOFT            =   0   'False
         PICPOS          =   0
         NGREY           =   0   'False
         FX              =   0
         HAND            =   0   'False
         CHECK           =   0   'False
         VALUE           =   0   'False
      End
      Begin VB.Frame Frame4 
         BackColor       =   &H00F7D9C2&
         Caption         =   "Product Listing"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2505
         Left            =   90
         TabIndex        =   5
         Top             =   2715
         Width           =   8970
         Begin MSComctlLib.ListView lvwList 
            Height          =   2130
            Left            =   120
            TabIndex        =   6
            Top             =   255
            Width           =   8730
            _ExtentX        =   15399
            _ExtentY        =   3757
            View            =   3
            Sorted          =   -1  'True
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            FullRowSelect   =   -1  'True
            GridLines       =   -1  'True
            HotTracking     =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   0
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            NumItems        =   15
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Product ID"
               Object.Width           =   2646
            EndProperty
            BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   1
               Text            =   "Description"
               Object.Width           =   4233
            EndProperty
            BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   2
               Text            =   "Warehouse"
               Object.Width           =   1764
            EndProperty
            BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   3
               Text            =   "Unit"
               Object.Width           =   1102
            EndProperty
            BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Alignment       =   1
               SubItemIndex    =   4
               Text            =   "Quantity"
               Object.Width           =   1587
            EndProperty
            BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Alignment       =   1
               SubItemIndex    =   5
               Text            =   "Price"
               Object.Width           =   2646
            EndProperty
            BeginProperty ColumnHeader(7) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Alignment       =   1
               SubItemIndex    =   6
               Text            =   "Amount"
               Object.Width           =   2646
            EndProperty
            BeginProperty ColumnHeader(8) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   7
               Text            =   "Reference Identity"
               Object.Width           =   0
            EndProperty
            BeginProperty ColumnHeader(9) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   8
               Text            =   "Cost"
               Object.Width           =   0
            EndProperty
            BeginProperty ColumnHeader(10) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   9
               Text            =   "Factor"
               Object.Width           =   0
            EndProperty
            BeginProperty ColumnHeader(11) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   10
               Text            =   "Long Desc"
               Object.Width           =   0
            EndProperty
            BeginProperty ColumnHeader(12) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   11
               Text            =   "Type"
               Object.Width           =   0
            EndProperty
            BeginProperty ColumnHeader(13) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   12
               Text            =   "Internal Barcode ID"
               Object.Width           =   2540
            EndProperty
            BeginProperty ColumnHeader(14) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   13
               Text            =   "Customer Code"
               Object.Width           =   2540
            EndProperty
            BeginProperty ColumnHeader(15) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               SubItemIndex    =   14
               Text            =   "Barcode/SKU"
               Object.Width           =   2540
            EndProperty
         End
      End
      Begin VB.Frame Frame1 
         BackColor       =   &H00F7D9C2&
         Height          =   2205
         Left            =   90
         TabIndex        =   0
         Top             =   450
         Width           =   8970
         Begin ITGControls.ITGTextBox txtPOType 
            Height          =   285
            Left            =   2040
            TabIndex        =   12
            Top             =   960
            Visible         =   0   'False
            Width           =   2355
            _ExtentX        =   3942
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Locked          =   -1  'True
            Label           =   "PO Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1000
            TextBoxWidth    =   1295
         End
         Begin MSComctlLib.ListView lvwRef 
            Height          =   1845
            Left            =   105
            TabIndex        =   1
            Top             =   225
            Width           =   1635
            _ExtentX        =   2884
            _ExtentY        =   3254
            View            =   3
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            FullRowSelect   =   -1  'True
            GridLines       =   -1  'True
            HotTracking     =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   0
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Reference No."
               Object.Width           =   2646
            EndProperty
         End
         Begin ITGControls.ITGTextBox txtCode 
            Height          =   285
            Left            =   2040
            TabIndex        =   2
            Top             =   240
            Width           =   2355
            _ExtentX        =   3942
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Locked          =   -1  'True
            Label           =   "Customer"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1000
            TextBoxWidth    =   1295
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   3075
            TabIndex        =   3
            Tag             =   "Order Date"
            Top             =   600
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   503
            Enabled         =   0   'False
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
            Mandatory       =   -1  'True
            DatePicker      =   0   'False
         End
         Begin ITGControls.ITGTextBox txtName 
            Height          =   285
            Left            =   4395
            TabIndex        =   4
            Top             =   240
            Width           =   4230
            _ExtentX        =   7355
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Locked          =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4170
         End
         Begin VB.Label Label1 
            BackColor       =   &H00F7D9C2&
            Caption         =   "DR Date"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   225
            Left            =   2080
            TabIndex        =   11
            Top             =   630
            Width           =   945
         End
      End
      Begin ITGControls.ComunionButton cmdUCAll 
         Height          =   375
         Left            =   1170
         TabIndex        =   8
         Top             =   5310
         Width           =   1065
         _ExtentX        =   1879
         _ExtentY        =   661
         BTYPE           =   3
         TX              =   "Uncheck All"
         ENAB            =   -1  'True
         BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         COLTYPE         =   1
         FOCUSR          =   -1  'True
         BCOL            =   15790320
         BCOLO           =   15790320
         FCOL            =   0
         FCOLO           =   0
         MCOL            =   12632256
         MPTR            =   1
         MICON           =   "frmRefList.frx":0F00
         UMCOL           =   -1  'True
         SOFT            =   0   'False
         PICPOS          =   0
         NGREY           =   0   'False
         FX              =   0
         HAND            =   0   'False
         CHECK           =   0   'False
         VALUE           =   0   'False
      End
      Begin ITGControls.ComunionButton cmdOK 
         Height          =   375
         Left            =   6900
         TabIndex        =   9
         Top             =   5310
         Width           =   1065
         _ExtentX        =   1879
         _ExtentY        =   661
         BTYPE           =   3
         TX              =   "&OK"
         ENAB            =   -1  'True
         BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         COLTYPE         =   1
         FOCUSR          =   -1  'True
         BCOL            =   15790320
         BCOLO           =   15790320
         FCOL            =   0
         FCOLO           =   0
         MCOL            =   12632256
         MPTR            =   1
         MICON           =   "frmRefList.frx":0F1C
         UMCOL           =   -1  'True
         SOFT            =   0   'False
         PICPOS          =   0
         NGREY           =   0   'False
         FX              =   0
         HAND            =   0   'False
         CHECK           =   0   'False
         VALUE           =   0   'False
      End
      Begin ITGControls.ComunionButton cmdCancel 
         Height          =   375
         Left            =   7980
         TabIndex        =   10
         Top             =   5310
         Width           =   1065
         _ExtentX        =   1879
         _ExtentY        =   661
         BTYPE           =   3
         TX              =   "&Cancel"
         ENAB            =   -1  'True
         BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         COLTYPE         =   1
         FOCUSR          =   -1  'True
         BCOL            =   15790320
         BCOLO           =   15790320
         FCOL            =   0
         FCOLO           =   0
         MCOL            =   12632256
         MPTR            =   1
         MICON           =   "frmRefList.frx":0F38
         UMCOL           =   -1  'True
         SOFT            =   0   'False
         PICPOS          =   0
         NGREY           =   0   'False
         FX              =   0
         HAND            =   0   'False
         CHECK           =   0   'False
         VALUE           =   0   'False
      End
   End
End
Attribute VB_Name = "frmRefList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.09.23

Option Explicit
Public MenuName As String

Enum eRefListType
    DR_Consignment
    DR_SalesCon
    DR_Corporate
    DR_Employee
    DR_Exhibit
    DR_Issues
    DR_Production
    DR_PurchaseReturn
    DR_Replacement
    DR_SampleDemo
    DR_Vans
    PO_PurchaseReq
    Sales_Corporate
    Sales_Consignment
    Sales_Delivery_Receipt
    Sales_Billing_Receipt
    Reimbursement
    Sales_Invoice
    Sales_Jobber
    Sales_Exhibit
    Sales_SampleDemo
    Sales_WalkIn
    WRR_Purchase
    WRR_NT_Production
    PurchaseInv
End Enum
Public mType As eRefListType

Public mRefPK As String
Public mItem As String
Public mDesc As String
Public mRefID As Long
Public sCode As String

Dim sCustCode As String


Private connHeader As New ADODB.Connection
Private connDetail As New ADODB.Connection
Private rsHeader As ADODB.Recordset
Private rsDetail As ADODB.Recordset

Private Sub cmdCAll_Click()
Dim i As Integer
    If lvwList.ListItems.Count = 0 Then Exit Sub
    For i = 1 To lvwList.ListItems.Count
        lvwList.ListItems(i).Checked = True
    Next i
End Sub

Private Sub cmdCancel_Click()
    Unload Me
    Set frmRefList = Nothing
End Sub

Private Sub cmdOK_Click()
Dim check As Boolean
If mType = Sales_Billing_Receipt Then
        For i = 1 To lvwList.ListItems.Count
                If lvwList.ListItems(i).Checked <> 0 Then
                    check = True
                End If
        Next i
        If check = True Then
                    FrmName.AddDetailsFromList
                    Unload Me
        Else
                    MsgBox "Please select from the list.", vbInformation, "Comunion"
                    Exit Sub
        End If
    Else
        FrmName.AddDetailsFromList
        Unload Me
End If
End Sub

Private Sub cmdUCAll_Click()
Dim i As Integer
    If lvwList.ListItems.Count = 0 Then Exit Sub
    For i = 1 To lvwList.ListItems.Count
        lvwList.ListItems(i).Checked = False
    Next i
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then
        Unload Me
        Set frmRefList = Nothing
    End If
End Sub

Private Sub Form_Load()
    Select Case mType
    
        Case DR_Consignment, DR_Corporate, DR_Employee, DR_Exhibit, DR_Issues, _
            DR_SampleDemo, DR_Vans, DR_SalesCon
            
            LoadToRecordset "erp_sp_RefSOforDR"
            fraRef.Caption = "Delivery Receipt List [Reference: Sales Order]"
            
        Case DR_Production
            
            LoadToRecordset "erp_sp_RefProductionforDR"
            fraRef.Caption = "Delivery Receipt List [Reference: Production]"
            
        Case DR_PurchaseReturn
            
            LoadToRecordset "erp_sp_RefPurchaseforReturn"
            fraRef.Caption = "Delivery Receipt List [Reference: WRR - Purchase]"
            
        Case DR_Replacement
            
            LoadToRecordset "erp_sp_RefWRRforReplacement"
            fraRef.Caption = "Delivery Receipt List [Reference: WRR - Replacement]"
            
        Case PO_PurchaseReq
            
            LoadToRecordset "erp_sp_RefPRForPO"
            fraRef.Caption = "Purchase Order List [Reference: Purchase Requisition]"
            
        Case Sales_Corporate, Sales_Consignment, Sales_Exhibit, Sales_Invoice, _
            Sales_Jobber, Sales_WalkIn
            
            LoadToRecordset "erp_sp_RefSOforDR"
            fraRef.Caption = "Sales Invoice List [Reference: Sales Order]"
            
        Case Sales_Delivery_Receipt, Sales_SampleDemo
            LoadToRecordset "erp_sp_RefDRforSI"
            fraRef.Caption = "Sales Invoice List [Reference: Delivery Receipt]"
            
        Case Sales_Billing_Receipt
            LoadToRecordset "erp_sp_RefBillingForSI"
            fraRef.Caption = "Sales Invoice List [Reference: Product File (Labor/Service)]"
            With lvwList                                                        ' gino code.
                .ColumnHeaders(3).Width = "0"
                .ColumnHeaders(13).Width = "0"
                .ColumnHeaders(14).Width = "0"
                .ColumnHeaders(15).Width = "0"
            End With
        Case Reimbursement
            LoadToRecordset "erp_sp_RefReimbursementForSI"
            fraRef.Caption = "Sales Invoice List [Reference: Product File (Reimbursement)]"
            With lvwList                                                        ' gino code.
                .ColumnHeaders(3).Width = "0"
                .ColumnHeaders(13).Width = "0"
                .ColumnHeaders(14).Width = "0"
                .ColumnHeaders(15).Width = "0"
            End With
        Case WRR_Purchase
            LoadToRecordset "erp_sp_RefPOForWRR"
            fraRef.Caption = "Warehouse Receiving List [Reference: Purchase Order]"
        
        Case WRR_NT_Production
            LoadToRecordset "erp_sp_RefPOForWRRNonTrade"
            fraRef.Caption = "Warehouse Receiving List [Reference: Purchase Order]"

        Case PurchaseInv
            LoadToRecordset "erp_sp_RefPOforPI"                ' if the company has no WRR
            With lvwList                                                        ' gino code.
                .ColumnHeaders(3).Width = "0"
                .ColumnHeaders(13).Width = "0"
                .ColumnHeaders(14).Width = "0"
                .ColumnHeaders(15).Width = "0"
            End With
            'LoadToRecordset "erp_sp_RefWRRforPI"
            fraRef.Caption = "Purchase Invoice List [Reference: PO]"
    End Select
    If lvwRef.ListItems.Count <> 0 Then lvwRef_ItemClick lvwRef.ListItems(lvwRef.SelectedItem.Index)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set connHeader = Nothing
    Set connDetail = Nothing
End Sub

Private Sub lvwList_GotFocus()
    If lvwList.ListItems.Count <> 0 Then lvwList_ItemClick lvwList.ListItems(lvwList.SelectedItem.Index)
End Sub

Private Sub lvwList_ItemClick(ByVal Item As MSComctlLib.ListItem)
    If lvwList.ListItems.Count = 0 Then Exit Sub
    mItem = Trim(lvwList.SelectedItem)
    mDesc = Trim(lvwList.SelectedItem.SubItems(1))
    mRefID = Trim(lvwList.SelectedItem.SubItems(7))
End Sub

Private Sub lvwList_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If lvwList.SelectedItem.Checked = True Then
            lvwList.SelectedItem.Checked = False
        Else
            lvwList.SelectedItem.Checked = True
        End If
    End If
End Sub

Private Sub lvwRef_ItemClick(ByVal Item As MSComctlLib.ListItem)
    If lvwRef.ListItems.Count = 0 Then Exit Sub
    mRefPK = Trim(lvwRef.SelectedItem)
    ListHeaderDetail
End Sub

Private Sub lvwRef_KeyPress(KeyAscii As Integer)
    If lvwRef.ListItems.Count = 0 Then Exit Sub
    If KeyAscii = 13 Then lvwRef_ItemClick lvwRef.ListItems(lvwRef.SelectedItem.Index)
End Sub
Sub LoadToRecordset(StoreProc As String)
On Error GoTo ErrHandler:

    Set rsHeader = New Recordset
    Set rsDetail = New Recordset
    
    OpenNewConnection connHeader
    OpenNewConnection connDetail
    
    connHeader.CommandTimeout = 100000
    sSQL = "exec " & StoreProc & " " & sCondition
    rsDetail.Open sSQL, connHeader, adOpenKeyset, adLockReadOnly
    
    With rsHeader.Fields
        .Append "cCompanyID", adBSTR, , adFldIsNullable
        .Append "cRefCode", adBSTR, , adFldIsNullable
        .Append "cRefName", adBSTR, , adFldIsNullable
        .Append "cRefNo", adBSTR, , adFldIsNullable
        Select Case mType 'Add by denz:11/2/2011
            Case PurchaseInv
                .Append "cPOType2", adBSTR, , adFldIsNullable
        End Select
    End With
    
    rsHeader.Open
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If Not ExistingWithinRecordset(rsHeader, "cRefNo = '" & Trim(rsDetail!cRefNo) & "' AND cCompanyID = '" & Trim(rsDetail!cCompanyID) & "'") Then
            rsHeader.AddNew
            rsHeader!cCompanyID = rsDetail!cCompanyID
            rsHeader!cRefCode = rsDetail!cRefCode
            rsHeader!cRefName = rsDetail!cRefName
            rsHeader!cRefNo = rsDetail!cRefNo
           Select Case mType
            Case PurchaseInv
                rsHeader!cPOType2 = rsDetail!cPOType2
                txtPOType.Visible = True
            End Select
        End If
        rsDetail.MoveNext
    Loop
    
    lvwRef.ListItems.Clear
    lvwList.ListItems.Clear
    If rsHeader.RecordCount <> 0 Then rsHeader.MoveFirst
    Do Until rsHeader.EOF
        Set itmX = lvwRef.ListItems.Add(, , Trim(rsHeader!cRefNo))
        rsHeader.MoveNext
    Loop
        
        
ErrHandler:
    If err.Number <> 0 Then
        MsgBox err.Number & err.Description, vbCritical, "Comunion"
        Exit Sub
    End If
End Sub


Sub ListHeaderDetail()
On Error Resume Next
    If lvwRef.ListItems.Count = 0 Then Exit Sub
    
    'Header
    rsHeader.Filter = "cRefNo = '" & Trim(lvwRef.SelectedItem) & "'"
    mRefPK = Trim(rsHeader!cRefNo)
    
    If rsHeader.RecordCount <> 0 Then
        txtCode = rsHeader!cRefCode & ""
        txtName = rsHeader!cRefName & ""
        dtbDate.Text = rsHeader!cRefDate
        txtPOType = rsHeader!cPOType2 'Add by denz:11/2/2011
    End If
    
    'Details
    rsDetail.Filter = "cRefNo = '" & Trim(lvwRef.SelectedItem) & "'"
    rsDetail.Sort = "nIdentity asc"
    
    lvwList.Checkboxes = True
    cmdCAll.Visible = True
    cmdUCAll.Visible = True
    
    lvwList.ListItems.Clear
    lvwList.Visible = False
    Do Until rsDetail.EOF
    
    If GetValueFrTable("lApproved", "production_fg", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'") = False Then
    
        Set itmX = lvwList.ListItems.Add(, , Trim(rsDetail!cItemNo) & "")
            itmX.SubItems(1) = Trim(rsDetail!cDesc) 'GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")
            itmX.SubItems(2) = Trim(rsDetail!cWH) & ""
            itmX.SubItems(3) = Trim(rsDetail!cUnit) & ""
            itmX.SubItems(4) = Format(rsDetail!nQty, "#,##0.#0") & ""
            itmX.SubItems(5) = Format(rsDetail!nPrice, "#,##0.###0") & ""
            itmX.SubItems(6) = Format(rsDetail!nAmount, "#,##0.#0") & ""
            itmX.SubItems(7) = rsDetail!nIdentity & ""
            itmX.SubItems(8) = Format(rsDetail!nCost, "#,##0.#0") & ""
            itmX.SubItems(9) = Format(rsDetail!nFactor, "#,##0.#0") & ""
            itmX.SubItems(10) = rsDetail!cLongDesc & ""
            itmX.SubItems(11) = rsDetail!cType & ""
            itmX.SubItems(12) = rsDetail!cBarcodeID & ""
            itmX.SubItems(13) = Format(rsDetail!cVatAmount, "#,##0.#0") & ""
            If mType = DR_Consignment Or mType = DR_Issues Or mType = DR_SalesCon Then
                If GetCustomerCode() = True Then itmX.SubItems(14) = sCustCode & ""
            Else
                itmX.SubItems(14) = ""
            End If
            
            If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'ITM_MAN_BARCODE'") = True Then
                itmX.SubItems(15) = rsDetail!cSKU & ""
            End If
            
    ElseIf GetValueFrTable("lApproved", "production_fg", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'") = False Or IsNull(GetValueFrTable("lApproved", "production_fg", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) = False Then
        If GetValueFrTable("lApproved", "production_fg", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'") = "" Then
            Set itmX = lvwList.ListItems.Add(, , Trim(rsDetail!cItemNo) & "")
            itmX.SubItems(1) = GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")
            itmX.SubItems(2) = Trim(rsDetail!cWH) & ""
            itmX.SubItems(3) = Trim(rsDetail!cUnit) & ""
            itmX.SubItems(4) = Format(rsDetail!nQty, "#,##0.##0") & ""
            itmX.SubItems(5) = Format(rsDetail!nPrice, "#,##0.##0") & ""
            itmX.SubItems(6) = Format(rsDetail!nAmount, "#,##0.##0") & ""
            itmX.SubItems(7) = rsDetail!nIdentity & ""
            itmX.SubItems(8) = Format(rsDetail!nCost, "#,##0.##0") & ""
            itmX.SubItems(9) = Format(rsDetail!nFactor, "#,##0.##0") & ""
            itmX.SubItems(10) = rsDetail!cLongDesc & ""
            itmX.SubItems(11) = rsDetail!cType & ""
            itmX.SubItems(12) = rsDetail!cBarcodeID & ""
            itmX.SubItems(13) = Format(rsDetail!cVatAmount, "#,##0.##0") & ""
            If mType = DR_Consignment Or mType = DR_Issues Or mType = DR_SalesCon Then
                If GetCustomerCode() = True Then itmX.SubItems(14) = sCustCode & ""
            Else
                itmX.SubItems(14) = ""
            End If
            If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'ITM_MAN_BARCODE'") = True Then
                itmX.SubItems(15) = rsDetail!cSKU & ""
            End If
        End If

    End If
  
    
        rsDetail.MoveNext
    Loop
    OtherItem
    lvwList.Visible = True
    If lvwList.ListItems.Count = 0 Then Exit Sub
    
End Sub

Function GetCustomerCode() As Boolean
On Error Resume Next
Dim rs As New ADODB.Recordset
Dim temp As String

sCustCode = ""
temp = sCode

If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode ='CLNT_MAN_USEPARENTCOMPANY'") = True Then
    If GetValueFrTable("cGroupCode", "CLIENT_CUSTOMER", "cCode = '" & temp & "'") <> "" Or _
        GetValueFrTable("cGroupCode", "CLIENT_CUSTOMER", "cCode = '" & temp & "'") <> Null Then
        
        sCode = GetValueFrTable("cGroupCode", "CLIENT_CUSTOMER", "cCode = '" & temp & "'")
        
    End If
End If

If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode ='ITM_MAN_USECUSTITEMNO'") = True Then
    Set rs = New ADODB.Recordset
    
    sSQL = "SELECT a.cStockNo FROM item_custcode a INNER JOIN item b " _
            & "ON b.cItemNo = a.cItemNo AND b.cPartNo = a.cBarcodeID AND b.cCompanyID = a.cCompanyID " _
            & "WHERE a.cItemNo = '" & Trim(rsDetail!cItemNo) & "'" _
            & " and a.cCode = (select cGroupCode from client_customer where cCode = '" & sCode & "' and cCompanyID = '" & COID & "')" ' '" & sCode & "'"
    rs.Open sSQL, cn, adOpenStatic, adLockOptimistic
    
    sCustCode = rs!cStockNo
    GetCustomerCode = True
End If
End Function

Sub OtherItem()
    Select Case mType
'        Case WRRSalesReturn
'            If lPullOutSlip Then Exit Sub
'            Set itmX = lvwList.ListItems.Add(, , "Other Item")
'            itmX.SubItems(1) = ""
'            itmX.SubItems(2) = ""
'            itmX.SubItems(3) = ""
'            itmX.SubItems(4) = "0"
'            itmX.SubItems(5) = "0"
'            itmX.SubItems(6) = "0"
'            itmX.SubItems(7) = "0"
        Case PO_PurchaseReq, WRR_Purchase
            Set itmX = lvwList.ListItems.Add(, , "Other Item")
            itmX.SubItems(1) = ""
            itmX.SubItems(2) = ""
            itmX.SubItems(3) = ""
            itmX.SubItems(4) = "0"
            itmX.SubItems(5) = "0"
            itmX.SubItems(6) = "0"
            itmX.SubItems(7) = "0"
            itmX.SubItems(8) = "0"
            itmX.SubItems(9) = "0"
            itmX.SubItems(10) = ""
            itmX.SubItems(11) = ""
    End Select
End Sub

